/**
 * 
 */
package org.myOrg.spetrum.GUI;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import org.myOrg.spetrum.Listener.MenuBarListener;
import org.myOrg.spetrum.util.Message;
import org.myOrg.spetrum.util.MessageMangement;
import org.myOrg.spetrum.util.MessageMangementImplement;
import org.myOrg.spetrum.util.OverallFactory;
import org.myOrg.spetrum.util.Reciver;

/**
 * 
 * @author XinTao Niu
 * 
 */
public class MenuBar extends JMenuBar implements Reciver {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	JMenu File;
	JMenuItem selectSuite;
	JMenuItem saveResult;
	JMenu Help;
	JMenuItem about;

	public MenuBar() {
		build();
	}

	private void build() {
		File = new JMenu("File");
		selectSuite = new JMenuItem("select Suite");
		saveResult = new JMenuItem("save result");
		Help = new JMenu("Help");
		about = new JMenuItem("about");

		File.add(selectSuite);
		File.add(saveResult);
		Help.add(about);

		selectSuite.addActionListener(new MenuBarListener());
		saveResult.addActionListener(new MenuBarListener());
		about.addActionListener(new MenuBarListener());
		
		saveResult.setEnabled(false);

		this.add(File);
		this.add(Help);

		this.register(MessageMangementImplement.RUNOVER,
				OverallFactory.getMessageManger());
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame frame = new JFrame();
		frame.setSize(500, 150);
		frame.setJMenuBar(new MenuBar());
		frame.setVisible(true);
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}

	@Override
	public void register(int messageType, MessageMangement messageManger) {
		// TODO Auto-generated method stub
		messageManger.register(this, messageType);
	}

	@Override
	public void handleMessage(Message msg) {
		// TODO Auto-generated method stub
		if(msg.getType() == MessageMangementImplement.RUNOVER){
			this.saveResult.setEnabled(true);
		}
	}

}
